package com.beisita.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet(displayName = "UserServlet", name = "UserServlet", urlPatterns = {"/user"}, loadOnStartup = 1, initParams = {@WebInitParam(name = "username", value = "\u5F20\u4E09")})
public class UserServlet extends HttpServlet {
    private String username;

    public UserServlet() {
        System.out.println("UserServlet...");
    }

    public void init(ServletConfig config) throws ServletException {
        this.username = config.getInitParameter("username");
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println(this.username);
        resp.getWriter().write("UserServlet access success");
    }
}